package com.example.thymeleaf.controller;

import com.example.thymeleaf.dao.BlogDao;
import com.example.thymeleaf.pojo.Blog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Controller
@RequestMapping("/")
public class BlogController {

    @Autowired
    BlogDao blogService;

    @GetMapping
    public String getBlogs(Model model) {
        List blogList=blogService.selectBlog();
        model.addAttribute("blogList",blogList);
        return "index";
    }

    @GetMapping("/blog")
    public String getBlog(Model model, @RequestParam(value = "id")  String blog_id) {
        Blog blog = blogService.selectBlogByID(Integer.parseInt(blog_id));
        model.addAttribute("blog",blog);
        return "blog_detail";
    }
}